package repository

import (
	"pq/models"
	"github.com/astaxie/beego/orm"
)

type ResourceRepository struct{

}

func (rr * ResourceRepository) ImportSubject(resrouce_id int,subjectEntity models.PqCsTestItem)(int64,error){
	subjectEntity.PqCsTestResourceId = resrouce_id
	//subjectEntity.Type =
	return orm.NewOrm().Update(&subjectEntity)
}

func (rr * ResourceRepository) GetLibSubjectByNumber(test_lib_id int,num int) models.PqCsTestItem{
	subjectEntity := models.PqCsTestItem{}
	slave := models.GetSlaveDb()
	slave.QueryTable("pq_cs_test_item").Filter("pq_cs_test_library_id",test_lib_id).Filter("ordering",num).One(&subjectEntity)
	return subjectEntity
}

func (rr * ResourceRepository) Create(test_lib_id int,body string)  {

}

func (rr * ResourceRepository) Delete(resource_id int)(int64,error){
	//slave := models.GetSlaveDb()
	master := models.GetMasterDb()
	//1.delete subjects
	master.Delete(&models.PqCsTestItem{PqCsTestResourceId:resource_id})
	//2.delete resource
	return master.Delete(&models.PqCsTestResource{Id:resource_id})
}
